<template>
	<view class="reg_out">
		<view class="boxcent">
			<text>Account:</text><input type="text" v-model="account" placeholder="请输入账号"><br>
			<text>Password:</text><input type="password" v-model="password" placeholder="请输入密码">
			<!-- <button class="btn1" @click="login">登录</button> -->
			<br>
			<br>
			<u-button @click="login" type="primary" 
			 text="登录"> 
			</u-button>
		</view>
		<view class="links">
			<view class="to">
				<navigator url="/pages/login/reg">去注册</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				account:'',password:'',list:{}
			}
		},
		methods: {
			async login(){
				var account = this.account;
				var password = this.password;
				// account.replace(/\s*/g,"")去除字符串内所有的空格
				if(account.replace(/\s*/g,"").length == 0){
					uni.showToast({
						icon:'error',
						position: 'bottom',
						title: '账号不能为空'
					})
				}else if(password.replace(/\s*/g,"").length ==0){
					uni.showToast({
						icon:'error',
						position: 'bottom',
						title: '密码不能为空'
					})
				}else{
					uni.request({
						url:'api/login/login_sp_ps',
						method:'POST',
						data:{account:account,password:password},
						success(res) {
							var result=res.data.data;
							console.log(result)
							if(res.data.code==200){
								
								uni.showToast({
									title: '登录成功'
								})
								// sessionStorage.setItem('account',result.account)
								// 
								uni.setStorageSync('account', result.account);
								uni.setStorageSync('user_type', result.user_type);
								uni.setStorageSync('supername', result.supername);
								uni.setStorageSync('sex', result.sex);
								
								
								uni.reLaunch({
									url:'/pages/super/home/home'
								})
							}else{
								uni.showToast({
									title:"密码错误"
								})
							}
						}
					})	
				}
			}
		}
	}
</script>

<style lang="scss">
	.reg_out{
		background-color: #f1f1f1;
		min-height: 100vh;
		overflow: hidden;
	}
	.links{
		margin: 55rpx;
		color: #23aaf2;
		letter-spacing: 4rpx;
		text-decoration: underline;
		font-weight: 500;
		font-size: 45rpx;
	}
	.boxcent{
		margin: 100rpx 50rpx;
		padding: 50rpx;
		box-sizing: border-box;
		background-color: #fff;
		border-radius: 20rpx;
		min-height: 500rpx;
		overflow: hidden;
		text{
			margin-left: 10px;
			font-size: 18px;
		}
		input{
			height: 40px;
			border-bottom: 1px solid #dbdbdb;  
		}
	}
	.btn1{
		margin-top: 50px;
		width: 60%;
	}
</style>
